#ifndef __ELFLOADER_H
#define __ELFLOADER_H
#include "stdtype.h"
#include "mxsetup.h"

/* default base address of kapp memory map */
#define MX_ELFLOADER_BASEADDR MXSETUP_KAPP_BASEADDR

/* label related */
#define MX_ELFLOADER_LABEL_MAGIC 0x7070616BU    // `k a p p`

/* the additional information of app */
typedef struct
{
    mx_uint32_t magic;      // must be `k a p p`
} mx_elfloader_label_t, *mx_elfloader_label_pt;

/**
 * function [ mx_elfloader_relx_repair ] implementation
 * @prototype: mx_bool_t mx_elfloader_relx_repair (mx_usize_t type, mx_addr_t repaddr, mx_addr_t symaddr);
 *      @param type: the relocation type
 *      @param repaddr: the code address which need to repair
 *      @param symaddr: the symbol address which use to repair
 *      @return: the result of repair operation
 * @desc: relocation table repair
 * @note: this function implement by arch/abi
 */
extern mx_bool_t mx_elfloader_relx_repair (mx_usize_t type, mx_addr_t repaddr, mx_addr_t symaddr);

/* the application entry point */
typedef mx_size_t (*kmain_pt) (mx_usize_t argc, char** argv);

/* calcute the memory size of elf that it need */
mx_usize_t mx_elfloader_memsize (mx_uint8_pt elf);
/* load elf to the specified address */
kmain_pt mx_elfloader (mx_uint8_pt elf, mx_void_pt addr);

#endif
